package com.sjm.bookshop.service.client;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sjm.bookshop.dao.OrderMapper;
import com.sjm.bookshop.entity.CountOfMonth;
import com.sjm.bookshop.entity.Orders;
import com.sjm.bookshop.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service
@Transactional
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    public List<Orders> orders(int i) {
        return orderMapper.selectList(i);

    }

    public List<User> getOrdersList() {

        return orderMapper.selectAllOrderList();
    }

    public int ConfirmOrder(String orderFId) {
        return orderMapper.Confirm(orderFId);
    }

    /**
     * 删除订单
     *
     * @param orderFId
     * @return
     */
    public int delOrder(String orderFId) {
        int res = 0;
        if (orderMapper.delOrderByOrderId(orderFId) > 0) {
            if (orderMapper.delOdByOrderId(orderFId) > 0) res = 1;
        } else {
            res = 0;
        }
        return res;
    }


    public int update(Orders orders) {
        return orderMapper.updateOrder(orders);
    }

    public void UpdateOrder(Orders orders) {
        orderMapper.updatebyPayOrder(orders);
        return;

    }

    /**
     * 月收入数据
     * @return
     */
    public List<CountOfMonth> getBoard() {
        List<CountOfMonth> data = orderMapper.getData();
        return data;
    }

    public  List<CountOfMonth> getListByCountOrder() {
        return orderMapper.listByLateDays();
    }

    public Integer CountOrderThirtyDays() {
        return orderMapper.ThirtyDayslist();
    }

    public List<CountOfMonth> getDaysCount(){
        return orderMapper.daysCount();
    }
}
